from sqlalchemy import Column, Integer, String, Boolean, DateTime, Text, JSON, Enum, Numeric
from sqlalchemy.sql import func
from app.core.database import Base
import enum


class CompetitionType(str, enum.Enum):
    DATA_SCIENCE = "data_science"
    HACKATHON = "hackathon"
    CODING_CHALLENGE = "coding_challenge"
    DESIGN_CONTEST = "design_contest"


class CompetitionStatus(str, enum.Enum):
    DRAFT = "draft"
    PUBLISHED = "published"
    ONGOING = "ongoing"
    ENDED = "ended"
    CANCELLED = "cancelled"


class DifficultyLevel(str, enum.Enum):
    BEGINNER = "beginner"
    INTERMEDIATE = "intermediate"
    ADVANCED = "advanced"
    EXPERT = "expert"


class Hackathon(Base):
    """简化的黑客马拉松/竞赛模型，匹配前端数据结构"""
    __tablename__ = "competitions"
    __table_args__ = {'extend_existing': True}

    id = Column(Integer, primary_key=True)
    title = Column(String(200), nullable=False)
    slug = Column(String(200), unique=True)
    description = Column(Text)
    short_description = Column(String(500))
    
    # 分类和标签
    type = Column(Enum(CompetitionType), nullable=False)
    category = Column(String(50))
    tags = Column(JSON, default=list)
    difficulty = Column(Enum(DifficultyLevel), default=DifficultyLevel.INTERMEDIATE)
    
    # 平台信息
    platform = Column(String(50))
    external_url = Column(String(500))
    
    # 奖励信息
    prize_pool = Column(String(50))
    prize_currency = Column(String(10), default="USD")
    prize_amount = Column(Numeric(12, 2))
    
    # 时间安排
    registration_start = Column(DateTime(timezone=True))
    registration_end = Column(DateTime(timezone=True))
    start_date = Column(DateTime(timezone=True))
    end_date = Column(DateTime(timezone=True))
    deadline = Column(DateTime(timezone=True), nullable=False)
    
    # 参与规则
    max_team_size = Column(Integer, default=5)
    min_team_size = Column(Integer, default=1)
    max_participants = Column(Integer)
    
    # 状态和统计
    status = Column(Enum(CompetitionStatus), default=CompetitionStatus.DRAFT)
    participants_count = Column(Integer, default=0)
    teams_count = Column(Integer, default=0)
    submissions_count = Column(Integer, default=0)
    
    # 媒体资源
    banner_image = Column(String(500))
    logo_image = Column(String(500))
    gallery_images = Column(JSON, default=list)
    
    # 详细信息
    rules = Column(Text)
    evaluation_criteria = Column(Text)
    resources = Column(JSON, default=list)
    
    # 元数据
    is_featured = Column(Boolean, default=False)
    is_public = Column(Boolean, default=True)
    view_count = Column(Integer, default=0)
    
    # 时间戳
    created_at = Column(DateTime(timezone=True), server_default=func.now())
    updated_at = Column(DateTime(timezone=True), onupdate=func.now())